package dao.impl;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import org.springframework.stereotype.Repository;

import dao.OrderDao;
import vo.Order;

@Repository("od")
public class OrderDaoImpl implements OrderDao {
	@PersistenceContext(name = "un")
	private EntityManager em;

	@Override
	public int updateOrderStatus(Integer oId) {
		Order order = em.find(Order.class, oId);
		order.setoStatus(2);

		return 1;
	}

	@Override
	public List<Order> findOrderByStatus(Integer mId, Integer oStatus) {
		String jpql = "select o from Order o where o.mId=:mId and o.oStatus=:oSatus";
		List<Order> orders = em.createQuery(jpql).setParameter("mId", mId).setParameter("oStatus", oStatus)
				.getResultList();
		if (orders.isEmpty()) {
			return null;
		} else {
			return orders;

		}
	}

}
